var api = require('../../utils/api.js');
var app = getApp();


Page({

  /**
   * 页面的初始数据
   */
  data: {
    zf: 0,
    zj: 0,
    goods: [],
    goodtit: '',
    show:0
  },

  onLoad(options) {
    this.setData({
      id: options.id
    })

    var that = this;
    api.get({
      url: 'wxapp/user/getorderbyid',
      data: {
        id: options.id
      },
      success: data => {
        console.log(data);
        that.setData({
          goods: data.data.list
        })
      }
    });

  },

  formSubmit(e) {
    console.log(e.detail.value)

    var that = this;
    var id = this.data.id;
    var data = e.detail.value;

    data.gid = id;
    data.goods = this.data.goodtit;

    console.log(data)

    api.get({
      url: 'wxapp/user/addorder',
      data: data,
      success: data => {
        wx.showToast({
          title: data.msg,
          icon: 'none'
        })

        if (data.code == 1) {
          setTimeout(function () {
            wx.navigateTo({
              url: '/pages/order/index',
            })
          }, 1500)
        }
      }
    });

  },

  onShow() {

    var that = this;

    api.get({
      url: 'wxapp/index/test',
      data: {},
      success: data => {
          console.log(data);

          that.setData({
            show: data.data.show
          })
      }
    })

    api.get({
      url: 'wxapp/user/getUserInfo',
      data: {},
      success: data => {
        console.log(data);
        var user = data.data;
        that.setData({
          user: user
        })

        if (!user.agentid) {

          wx.showModal({
            title: '提示',
            content: '你还未进行认证!',
            showCancel: false,
            success(res) {
              if (res.confirm) {
                wx.navigateTo({
                  url: '/pages/rz/index',
                })
              }
            }
          })
        }
      }
    });

  },

  bindPickerChange(ret) {
    console.log(ret);
    var index = ret.detail.value;
    var goods = this.data.goods;



    this.setData({
      index: ret.detail.value,
      goodtit: goods[index]
    })


  },



  radioChangezj(ret) {
    console.log(ret);
    this.setData({
      zj: ret.detail.value
    })
  }

})